# -*- coding: utf-8 -*-
import scrapy
from ..items import InfoItem


class ZfzbggSpider(scrapy.Spider):
    name = 'zfzbgg'
    allowed_domains = ['http://ggzy.wzzbtb.com']
    start_urls = ['http://ggzy.wzzbtb.com/wzcms/zfcgzbgg/index.htm']

    def parse(self, response):
        info = InfoItem()
        sels = response.css('div.List-Li.FloatL ul li')
        for sel in sels:
            info['time'] = sel.xpath('./span/text()').extract()
            info['title'] = sel.xpath('./a/@title').extract()
            info['link'] = self.allowed_domains[0] + \
                sel.xpath('./a/@href').extract_first()
            yield info
        ne = response.css('div.Zy-Page.FloatL div')
        a = ne.xpath('./a')
        next_url = a[2].xpath('@href').extract_first()
        if next_url:
            next_url = 'http://ggzy.wzzbtb.com/wzcms/zfcgzbgg/' + next_url
            yield scrapy.Request(next_url, callback=self.parse, dont_filter=True)
